<template>
  <tl-sub-page :visible.sync="visible" :title="title" v-dialogDrag class="tl-dialog" @open="open" @close="close">
    <el-form class="tl-form" ref="form" :model="model" :rules="rules" label-width="120px" :disabled="disableEditSubmit">
      <el-row>
        <el-col :span="12">
          <el-form-item label="位置" prop="location" :rules="rules.validateRequire">
            <el-select v-model="model.location">
              <el-option v-for="item in codeModel.locationList" :key="item.code" :label="item.name" :value="item.code" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="名称" prop="name" :rules="rules.validateRequire">
            <el-input v-model="model.name" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="职能部门" prop="deptcode" :rules="rules.validateRequire">
            <tl-ref-tree v-model="model.deptcode" :initDisplayData.sync="model.dispdeptcode" dataType="code" :queryTreeUrl="url.queryDeptTree" :queryDataUrl="url.queryDeptList" :singleSelect="true"></tl-ref-tree>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="负责人" prop="usercode" :rules="rules.validateRequire">
            <tl-ref-user v-model="model.usercode" :initDisplayData.sync="model.username" dataType="code" :singleSelect="true" @confirm="queryUserInfo"></tl-ref-user>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="联系电话" prop="telephone">
            <el-input v-model="model.telephone" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="会议室性能" prop="performance">
            <el-input v-model="model.performance" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="会议室容量" prop="capacity">
            <el-input v-model="model.capacity" placeholder="可承载人数">
              <template slot="append">
                人
              </template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="会议室面积" prop="square">
            <el-input v-model="model.square">
              <template slot="append">
                平米
              </template>
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="配套资源">
            <el-checkbox-group v-model="selectedSourceList">
              <el-checkbox v-for="item in allSourceList" :key="item.id" :label="item.id.toString()" >{{item.name}}</el-checkbox>
            </el-checkbox-group>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="备注" prop="description">
            <el-input v-model="model.description" type="textarea" :rows="4" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="排序号" prop="sortcode">
            <el-input-number v-model="model.sortcode" :min="0" :max="10000"></el-input-number>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="有效" prop="enabled">
            <el-radio-group v-model="model.enabled">
              <el-radio :label="parseInt(item.code)" :key="item.code" v-for="item in codeModel.enabledList">{{ item.name }}</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button :type="disableEditSubmit === false ? 'text' : 'primary'" @click="doCancelEdit">取消</el-button>
      <el-button type="primary" @click="doSubmitEdit" :loading="saveLoading" v-if="disableEditSubmit === false">确认</el-button>
    </div>
  </tl-sub-page>
</template>

<script>
/** mixins */
import { queryDataCode } from "@tapui/api/dataCode"
import { mixin_edit } from "@tapui/mixins/mixin_edit"
import { putAction, getAction, postAction } from "@tapui/utils/http"
export default {
  mixins: [mixin_edit],
  data() {
    return {
      moduleTitle: "会议室档案",
      url: {
        add: "/toa/boardroomItem/insert",
        edit: "/toa/boardroomItem/update",
        load: "/toa/boardroomItem/load",
        queryCodeList: "/toa/boardroomItem/dataCodeList",
        queryDeptTree: "/cbo/dept/queryTreeList",
        queryDeptList: "/cbo/dept/list",
        queryUserInfo: "/cbo/user/load",
        queryBoardroomSourceList: "/toa/boardroomSource/list"
      },
      // 会议室资源可选列表
      allSourceList: [],
      selectedSourceList: []
    }
  },
  methods: {
    queryUserInfo(userList) {
      if (userList && userList.length > 0) {
        getAction(this.url.queryUserInfo, { id: userList[0].id }).then(data => {
          if (data.success) {
            this.$set(this.model, "telephone", data.result.mobile)
          }
        })
      }
    },
    beforeSubmit() {
      this.model.sourcelist = this.selectedSourceList.join(",")
      return true
    },
    loaded() {
      getAction(this.url.queryBoardroomSourceList, {
        sidx: "sortcode",
        sord: "asc",
        currentPage: 1,
        pageSize: 9999,
        qry_enabled: 1
      }).then(data => {
        if (data.success) {
          this.allSourceList = data.result.dataList
        }
      })
      if (this.model.sourcelist) {
        this.selectedSourceList = this.model.sourcelist.split(",")
      } else {
        this.selectedSourceList = []
      }
    }
  }
}
</script>

<style scoped></style>
